module AutoBase
  class Message < String
    def initialize(text, matches = nil)
      (matches || []).each do |matcher|
        if matcher.match(text)
          @match = matcher
          break
        end
      end
      
      super(text)
    end
    
    def [](name)
      @match.matches[name]
    end

    def raw; self;end

    class << self
      @@workers = {}
      def register(meth, klass, type = nil)
        @@workers[[meth, type]] = klass

        class_eval %Q{
          def #{meth}(type = nil)
            @@workers[[:#{meth}, type]].new(@text)
          end
        }
      end
    end
  end
end